var a = getApp();

Page({
    data: {
        member_id: "",
        information: {
            my_name: "",
            phone_number: "",
            store_name: "",
            store_logo: "",
            bank_account: "",
            owner_name: "",
            opening_bank: "",
            opening_branch: "",
            enterprise_alipay: "",
            enterprise_alipay_user: "",
            alipay: "",
            alipay_username: "",
            weChat_account: "",
            category: "",
            group: "",
            imageList: ""
        },
        imageUrl: "",
        jumpState: !0,
        fill_set: ""
    },
    onLoad: function(a) {
        a.member_id && this.setData({
            member_id: a.member_id
        }), this._getFillSet(), this._getJson();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    _getFillSet: function() {
        var t = this, n = a.getNetAddresss("plugin.supplier.frontend.info.getFillSet");
        a._postNetWork({
            url: n,
            showToastIn: !1,
            data: {},
            success: function(a) {
                var n = a.data;
                1 == n.result ? (t.setData({
                    fill_set: n.data.fill_set ? n.data.fill_set : ""
                }), console.log(t.data.fill_set)) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    _getJson: function() {
        var t = this, n = a.getNetAddresss("plugin.supplier.frontend.info.index");
        a._postNetWork({
            url: n,
            showToastIn: !1,
            data: {
                member_id: t.data.member_id
            },
            success: function(a) {
                var n = a.data;
                console.log(a, "resdata"), 1 == n.result ? t.setData({
                    "information.my_name": n.data.realname ? n.data.realname : "",
                    "information.phone_number": n.data.mobile ? n.data.mobile : "",
                    "information.store_name": n.data.store_name ? n.data.store_name : "",
                    "information.store_logo": n.data.logo ? n.data.logo : "",
                    imageUrl: n.data.logo ? n.data.logo : "",
                    "information.bank_account": n.data.company_bank ? n.data.company_bank : "",
                    "information.owner_name": n.data.bank_username ? n.data.bank_username : "",
                    "information.opening_bank": n.data.bank_of_accounts ? n.data.bank_of_accounts : "",
                    "information.opening_branch": n.data.opening_branch ? n.data.opening_branch : "",
                    "information.enterprise_alipay": n.data.company_ali ? n.data.company_ali : "",
                    "information.enterprise_alipay_user": n.data.company_ali_username ? n.data.company_ali_username : "",
                    "information.alipay": n.data.ali ? n.data.ali : "",
                    "information.alipay_username": n.data.ali_username ? n.data.ali_username : "",
                    "information.weChat_account": n.data.wechat ? n.data.wechat : "",
                    "information.category": n.data.has_one_category ? n.data.has_one_category.title : "默认行业",
                    "information.group": n.data.has_one_group ? n.data.has_one_group.title : "默认分组",
                    "information.imageList": n.data.has_one_aptitude.aptitude ? n.data.has_one_aptitude.aptitude : ""
                }) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(a) {}
        });
    },
    myNameinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.my_name": t
        });
    },
    phoneNumberinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.phone_number": t
        });
    },
    storeNameinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.store_name": t
        });
    },
    bankAccountinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.bank_account": t
        });
    },
    ownerNameinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.owner_name": t
        });
    },
    openingBankinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.opening_bank": t
        });
    },
    openingBranchinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.opening_branch": t
        });
    },
    enterpriseAlipayinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.enterprise_alipay": t
        });
    },
    enterpriseAlipayUserinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.enterprise_alipay_user": t
        });
    },
    alipayinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.alipay": t
        });
    },
    alipayUsernameinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.alipay_username": t
        });
    },
    weChatAccountinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "information.weChat_account": t
        });
    },
    onRead: function() {
        var t = this, n = wx.getStorageSync("wx_token"), i = wx.getStorageSync("session"), e = a.getNetAddresss("plugin.supplier.frontend.info.upload");
        e += "&3rd_session=" + i, wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var i = a.tempFilePaths;
                console.log(i[0]), wx.compressImage({
                    src: i[0],
                    quality: 60,
                    success: function(a) {
                        var i = a.tempFilePath;
                        console.log("eee", a), wx.uploadFile({
                            url: e,
                            filePath: i,
                            name: "file",
                            header: {
                                "Content-Type": "multipart/form-data",
                                Cookie: "PHPSESSID=" + n
                            },
                            success: function(a) {
                                var n = JSON.parse(a.data);
                                1 == n.result ? t.setData({
                                    imageUrl: i,
                                    "information.store_logo": n.data.img
                                }) : wx.showToast({
                                    icon: "none",
                                    title: n.msg,
                                    duration: 1500
                                });
                            }
                        });
                    },
                    fail: function(a) {},
                    complete: function(a) {}
                });
            }
        });
    },
    jumpJudge: function() {
        this.setData({
            jumpState: !0
        }), this.data.information.my_name && this.data.information.phone_number && this.data.information.store_name && this.data.information.store_logo || this.setData({
            jumpState: !1
        }), this.data.fill_set && ("1" == this.data.fill_set.company_bank && "" == this.data.information.bank_account && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.bank_username && "" == this.data.information.owner_name && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.bank_of_accounts && "" == this.data.information.opening_bank && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.opening_branch && "" == this.data.information.opening_branch && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.company_ali && "" == this.data.information.enterprise_alipay && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.company_ali_username && "" == this.data.information.enterprise_alipay_user && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.ali && "" == this.data.information.alipay && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.ali_username && "" == this.data.information.alipay_username && this.setData({
            jumpState: !1
        }), "1" == this.data.fill_set.wechat && "" == this.data.information.weChat_account && this.setData({
            jumpState: !1
        })), "" == this.data.imageUrl && this.setData({
            jumpState: !1
        });
    },
    modifyInformation: function() {
        if (this.jumpJudge(), this.data.jumpState) {
            if (a._isMoblie(this.data.information.phone_number)) return void wx.showToast({
                icon: "none",
                title: "请输入正确的手机号",
                duration: 1500
            });
            if ("1" == this.data.fill_set.company_bank && !/^[0-9]*$/.test(this.data.information.bank_account)) return void wx.showToast({
                icon: "none",
                title: "请输入正确的银行卡账号",
                duration: 1500
            });
            if ("1" == this.data.fill_set.company_ali && !/^[a-zA-Z\d._-]*\@[a-zA-Z\d.-]{1,10}\.[a-zA-Z\d]{1,20}$/.test(this.data.information.enterprise_alipay)) return void wx.showToast({
                icon: "none",
                title: "请输入正确的企业支付宝账号",
                duration: 1500
            });
            if ("1" == this.data.fill_set.ali && !/^(?:1[3-9]\d{9}|[a-zA-Z\d._-]*\@[a-zA-Z\d.-]{1,10}\.[a-zA-Z\d]{1,20})$/.test(this.data.information.alipay)) return void wx.showToast({
                icon: "none",
                title: "请输入正确的支付宝账号",
                duration: 1500
            });
            if ("1" == this.data.fill_set.wechat && !/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(this.data.weChat_account)) return void wx.showToast({
                icon: "none",
                title: "请输入正确的微信号",
                duration: 1500
            });
            var t = {
                realname: this.data.information.my_name,
                mobile: this.data.information.phone_number,
                store_name: this.data.information.store_name,
                logo: this.data.information.store_logo,
                company_bank: this.data.information.bank_account,
                bank_username: this.data.information.owner_name,
                bank_of_accounts: this.data.information.opening_bank,
                opening_branch: this.data.information.opening_branch,
                company_ali: this.data.information.enterprise_alipay,
                company_ali_username: this.data.information.enterprise_alipay_user,
                ali: this.data.information.alipay,
                ali_username: this.data.information.alipay_username,
                wechat: this.data.information.weChat_account
            }, n = a.getNetAddresss("plugin.supplier.frontend.info.edit");
            a._postNetWork({
                url: n,
                showToastIn: !1,
                data: t,
                success: function(a) {
                    var t = a.data;
                    1 == t.result ? wx.showToast({
                        title: "修改成功",
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    }) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1500
                    });
                },
                fail: function(a) {}
            });
        } else wx.showToast({
            icon: "none",
            title: "填写信息不完整",
            duration: 1500
        });
    }
});